package com.rc.saas.tenant.controller.ugs;

import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.WebPageInfo;
import com.rc.saas.tenant.search.member.MemberAccountRecordSearch;
import com.rc.saas.tenant.search.member.MemberPointRecordSearch;
import com.rc.saas.tenant.service.member.MemberAccountRecordService;
import com.rc.saas.tenant.service.ugs.UgsMemberPointRecordService;
import com.rc.saas.tenant.vo.member.MemberAccountRecordResultVo;
import com.rc.saas.tenant.vo.member.MemberPointRecordResultVo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/ugsMemberPointRecord")
public class UgsMemberPointRecordController {
    private static Logger logger = LogManager.getLogger(UgsMemberPointRecordController.class);

    @Autowired
    private UgsMemberPointRecordService ugsMemberPointRecordService;

    /**
     * 跳转积分变动页面
     *
     * @return
     */
    @RequestMapping(value = "/ugsMemberPointRecord/{memberId}", method = RequestMethod.GET)
    public String ugsMemberPointRecordPage(@PathVariable("memberId") Long memberId, Model model) {
        model.addAttribute("memberId", memberId);
        return "/templates/ugs/ugsMemberPointRecord";
    }

    /**
     * 返回积分变动列表数据
     *
     * @return
     */
    @RequestMapping(value = "/listMemberPointRecord", method = RequestMethod.GET)
    @ResponseBody
    public WebPageInfo listMemberPointRecord(MemberPointRecordSearch memberPointRecordSearch) {
        PageInfo<MemberPointRecordResultVo> pageInfo = ugsMemberPointRecordService.searchByCondition(memberPointRecordSearch);
        WebPageInfo webPageInfo = new WebPageInfo(pageInfo.getList(), Long.valueOf(pageInfo.getTotal()).intValue());
        return webPageInfo;
    }
}
